< previous page page_174 next page >

Page 174
application against user expectations before making a major commitment to deploying it on a large scale. Beta testing is also a good way of seeing the effectiveness of your self-testing methods against the way demanding users treat your application.
In general, self-testing objects are the best ways to localize errors of any sort in your application. Tests that fail can be better traced to classes and methods because the responsibilities of methods are highlighted by self-testing policies. Finally, having self-testing methods in your objects identifies you as a conscientious supporter of testing, something that will endear you to your testers during your project's testing cycles.
As indicated, checking preconditions and postconditions upon invoking a method is an important part of localizing errors. Building these mechanisms into your Visual Basic classes includes
Using argument data type checking
Using return data type checking
Using Argument Data Type Checking
The task of implementing type checking for arguments of Visual Basic types seems pretty simple, you might think. Simply specify the data type of the argument in the argument list, and let Visual Basic handle the rest. This strategy might work for incoming parameters of the same data type as expected by the respective argument, but what about parameters of type Variant? You must prepare for type mismatch errors with respect to the Variant data type and any other user-defined object types. Let's look at some examples.
Suppose you have a class with a method as follows:
Public Sub testMethod(ByVal argString As String)
    MsgBox argString
End Sub
Further, suppose this class has another method as follows:
Public Sub tryThis()
    Dim vTestData As Variant
    vTestData = 
www.samsona.com
    testMethod vTestData
End Sub
Notice that the method, testMethod, expects incoming parameters to be of the String data type. However, you passed in a Variant (vTestData) that stores a String value. Happily, the method tryThis accepts this parameter as a valid argument. However, let's change the type of argString from String to Integer:
Public Sub testMethod(ByVal argInteger As Integer)
    MsgBox argString
End Sub

 
< previous page page_174 next page >

If you like this book, buy it!